package com.atguigu.gulimall.order.vo;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author 满超
 * @date 2020/06/26
 **/
public class OrderVo {
    //收货地址列表
    List<MemberAddressVo> address;

    //所有选中的购物项
    List<OrderItemsVo> items;

    //优惠信息
    Integer integer;

    //订单总额
    BigDecimal total;

    //实付金额
    BigDecimal payTotal;

    //总数量
    Integer count;

    //库存
    Map<Long, Boolean> stocks;

    public Map<Long, Boolean> getStocks() {
        return stocks;
    }

    public void setStocks(Map<Long, Boolean> stocks) {
        this.stocks = stocks;
    }

    public Integer getCount() {
        int count = 0;
        if (items != null) {
            for (OrderItemsVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    //防止重复提交令牌
    String orderToken;

    public String getOrderToken() {
        return orderToken;
    }

    public void setOrderToken(String orderToken) {
        this.orderToken = orderToken;
    }

    public List<MemberAddressVo> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVo> address) {
        this.address = address;
    }

    public List<OrderItemsVo> getItems() {
        return items;
    }

    public void setItems(List<OrderItemsVo> items) {
        this.items = items;
    }


    public void setCount(Integer count) {
        this.count = count;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null) {
            for (OrderItemsVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    public void setTotal(BigDecimal total) {
        this.total = total;
    }

    public BigDecimal getPayTotal() {
        return total;
    }

    public Integer getInteger() {
        return integer;
    }

    public void setInteger(Integer integer) {
        this.integer = integer;
    }

    public void setPayTotal(BigDecimal payTotal) {
        this.payTotal = payTotal.subtract(BigDecimal.valueOf(this.integer));
    }
}
